package com.easyaop.api.support;

import java.lang.invoke.CallSite;
import java.lang.invoke.LambdaConversionException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.Objects;

public class CustomMetaFactory {
    public static CallSite metaFactory(MethodHandles.Lookup caller,
                                       String interfaceMethodName,
                                       MethodType factoryType,
                                       MethodType interfaceMethodType,
                                       MethodHandle implementation,
                                       MethodType dynamicMethodType) throws LambdaConversionException {
        AbstractValidatingLambdaMetaFactory factory = new CustomInnerClassMetaFactory(Objects.requireNonNull(caller),
                Objects.requireNonNull(factoryType),
                Objects.requireNonNull(interfaceMethodName),
                Objects.requireNonNull(interfaceMethodType),
                Objects.requireNonNull(implementation),
                Objects.requireNonNull(dynamicMethodType));
        factory.validateMetaFactoryArgs();
        return factory.buildCallSite();
    }
}